﻿using System;
using System.Windows.Forms;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Tools.Helper;
using System.Text;

namespace Tools
{
    public partial class VerifyOper : MUserControl
    {
        public VerifyOper()
        {
            InitializeComponent();
        }

        #region 正则表达式验证

        private void button1_Click(object sender, EventArgs e)
        {
            string pattern = this.textBox1.Text;
            string inputStr = this.textBox2.Text;

            if (string.IsNullOrWhiteSpace(pattern))
            {
                label3.Text = "请输入正则表达式";
                return;
            }

            if (string.IsNullOrWhiteSpace(inputStr))
            {
                label3.Text = "请输入验证字符串";
                return;
            }

            pattern = pattern.Trim();
            inputStr = inputStr.Trim();

            if (Regex.IsMatch(inputStr, pattern))
            {
                label3.Text = "验证通过";
                return;
            }

            label3.Text = "验证不通过";
        }

        #endregion



        private void t4btn1_Click(object sender, EventArgs e)
        {
            JavascriptFormater formater = new JavascriptFormater();
            formater.InvokeFormatCompleted += new InvokeScriptCompletedEventHandler(formater_InvokeFormatCompleted2);
            formater.FormatAsync(t4rtb1.Text.Trim());
        }

        void formater_InvokeFormatCompleted2(InvokeScriptCompletedEventArgs e)
        {
            if (e.Result != null)
                t4rtb1.Text = e.Result.ToString();
        }

        #region Json

        private void t3btn1_Click(object sender, EventArgs e)
        {
            JsonFormater formater = new JsonFormater();
            formater.InvokeFormatCompleted += new InvokeScriptCompletedEventHandler(formater_InvokeFormatCompleted);
            formater.FormatAsync(t3rtb1.Text.Trim());
        }

        void formater_InvokeFormatCompleted(InvokeScriptCompletedEventArgs e)
        {
            if (e.Result != null)
                t3rtb1.Text = e.Result.ToString();
        }

        #endregion
    }
}
